package com.easy.easy.Service.impl;

import com.easy.easy.Service.IProductService;
import com.easy.easy.bean.Category;
import com.easy.easy.bean.Product;
import com.easy.easy.dao.ProductDao;
import com.easy.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
@Service
public class ProductServiceimpl implements IProductService {

    @Autowired
    ProductDao productDao;

    @Override
    public int add(Product product) {
        return productDao.add(product);
    }

    @Override
    public int delete(int id) {
        return productDao.delete(id);
    }

    @Override
    public int edit(Product product) {
        return productDao.edit(product);
    }

    @Override
    public Product getByID(int id) {
        return productDao.getByID(id);
    }

    @Override
    public List<Product> getList(Page page, String text) {
        return productDao.getList(page, text);
    }

    @Override
    public List<Category> getChildren(Integer id) {
        return productDao.getChildren(id);
    }

    @Override
    public int getCount(String text) {
        return productDao.getCount(text);
    }

    @Override
    public List<Category> getParent(Integer id) {
        return productDao.getParent(id);
    }

    @Override
    public List<Product> getAll() {
        return productDao.getAll();
    }

    @Override
    public List<Product> getlist(Page page, String text) {
        // 确保分页参数有效
        if(page.getLimit() <= 0) page.setLimit(10);
        return productDao.getList(page, text);
    }

}
